package cn.fz.eventdemo01.publisher;

import cn.fz.eventdemo01.event.LoginEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

/**
 * 创建事件发布者
 * 创建一个事件发布者，用于发布用户登录事件：
 */
@Service
public class LoginEventPublisher {
    private final ApplicationEventPublisher applicationEventPublisher;

    public LoginEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }

    public void publishLoginEvent(String username) {
        applicationEventPublisher.publishEvent(new LoginEvent(this, username));
    }
}
